package com.hzdl.car.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hzdl.car.bean.Menu;
import com.hzdl.car.bean.Role;
import com.hzdl.car.mapper.RoleMapper;
import com.hzdl.car.service.RoleService;
import com.hzdl.car.vo.RoleVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class RoleServiceImpl implements RoleService {
    @Autowired
    private RoleMapper rm;

    @Override
    public PageInfo findByWhere(RoleVo roleVo) {
        PageHelper.startPage(roleVo.getPage(),roleVo.getLimit());
        List<Role> rList = rm.findByWhere(roleVo);
        PageInfo pageInfo = new PageInfo(rList);
        return pageInfo;
    }

    @Override
    public List<Menu> findMenuByRoleid(Integer roleid) {
        return rm.findMenuByRoleid(roleid);
    }

    @Override
    public int roleMenu(RoleVo roleVo) {
        int row = rm.deleteRoleMenuByRid(roleVo);
        row+=rm.addRoleMenu(roleVo);
        return row;
    }

    @Override
    public int addRole(RoleVo roleVo) {
        return rm.addRole(roleVo);
    }

    @Override
    public int updateRole(RoleVo roleVo) {
        return rm.updateRole(roleVo);
    }

    @Override
    public int deleteRole(RoleVo roleVo) {
        int row=rm.deleteRole(roleVo);
        row+=rm.deleteRoleMenuByRid(roleVo);
        row+=rm.deleteRoleUserByRid(roleVo);
        return row;
    }

    @Override
    public int deleteRoleMenuByRoleId(Integer id) {
        return rm.deleteRoleMenuByRoleId(id);
    }


}
